﻿/*
==================================================================
    注意：此文件为Auto代码，不可手动修改【监管部门用户】
==================================================================
*/

namespace Services
{
    /// <summary>
    /// Auto监管部门用户
    /// </summary>
    public abstract class AutoRegulatorUserMapping : BaseMapping<RegulatorUser, RegulatorUserModel, RegulatorUserFilterModel>
    {
        public AutoRegulatorUserMapping(ICurrentUser currentUser)
            : base(currentUser) { }

        #region 读数据
        /// <summary>
        /// 读数据，从Entity对象转成Model对象
        /// </summary>
        /// <param name="entity">Entity对象</param>
        /// <returns></returns>
        public override RegulatorUserModel Entity2Model(RegulatorUser entity)
        {
            RegulatorUserModel model = new RegulatorUserModel();

            model.RegulatorUserID = entity.RegulatorUserID;
            model.RegulatorID = entity.RegulatorID;
            model.LoginName = entity.LoginName;
            model.LoginPassword = entity.LoginPassword;
            model.Name = entity.Name;
            model.IsDelete = entity.IsDelete;
            model.Remark = entity.Remark;
            model.CreateDate = entity.CreateDate;

            return model;
        }
        #endregion

        #region 写数据
        /// <summary>
        /// 写数据，从Model对象转换成Entity对象
        /// </summary>
        /// <param name="model">ViewModel对象</param>
        /// <returns></returns>
        public override RegulatorUser Model2Entity(RegulatorUserModel model)
        {
            RegulatorUser entity = new RegulatorUser();

            entity.RegulatorUserID = model.RegulatorUserID;
            entity.RegulatorID = model.RegulatorID;
            entity.LoginName = model.LoginName;
            entity.LoginPassword = model.LoginPassword;
            entity.Name = model.Name;
            entity.IsDelete = model.IsDelete;
            entity.Remark = model.Remark;
            entity.CreateDate = model.CreateDate;

            return entity;
        }
        #endregion

        #region 搜索条件转换
        /// <summary>
        /// 搜索条件转换，从FilterModel对象转换成Where对象
        /// </summary>
        /// <param name="filterModel">FilterModel对象</param>
        /// <returns></returns>
        public override Expressionable<RegulatorUser> FilterModel2Where(RegulatorUserFilterModel filterModel)
        {
            var where = base.FilterModel2Where(filterModel);

            //编号
            if (filterModel._RegulatorUserID.HasValue)
            {
                where = where.And(x => x.RegulatorUserID == filterModel._RegulatorUserID.Value);
            }
            if (filterModel._RegulatorUserIDs.IsNotEmpty() && filterModel._RegulatorUserIDs.Count > 0)
            {
                where = where.And(x => filterModel._RegulatorUserIDs.Contains(x.RegulatorUserID));
            }
            if (filterModel._NotRegulatorUserIDs.IsNotEmpty() && filterModel._NotRegulatorUserIDs.Count > 0)
            {
                where = where.And(x => !filterModel._NotRegulatorUserIDs.Contains(x.RegulatorUserID));
            }

            //监管部门
            if (filterModel._RegulatorID.HasValue)
            {
                where = where.And(x => x.RegulatorID == filterModel._RegulatorID.Value);
            }
            if (filterModel._RegulatorIDs.IsNotEmpty() && filterModel._RegulatorIDs.Count > 0)
            {
                where = where.And(x => filterModel._RegulatorIDs.Contains(x.RegulatorID));
            }
            if (filterModel._NotRegulatorIDs.IsNotEmpty() && filterModel._NotRegulatorIDs.Count > 0)
            {
                where = where.And(x => !filterModel._NotRegulatorIDs.Contains(x.RegulatorID));
            }

            //登录名
            if (!string.IsNullOrEmpty(filterModel._LoginName))
            {
                where = where.And(x => x.LoginName.Contains(filterModel._LoginName));
            }
            if (!string.IsNullOrEmpty(filterModel._LoginNameEqual))
            {
                where = where.And(x => x.LoginName == filterModel._LoginNameEqual);
            }

            //姓名
            if (!string.IsNullOrEmpty(filterModel._Name))
            {
                where = where.And(x => x.Name.Contains(filterModel._Name));
            }
            if (!string.IsNullOrEmpty(filterModel._NameEqual))
            {
                where = where.And(x => x.Name == filterModel._NameEqual);
            }

            //是否删除
            if (filterModel._IsDelete.HasValue)
            {
                where = where.And(x => x.IsDelete == filterModel._IsDelete.Value);
            }
            if (filterModel._IsDeletes.IsNotEmpty() && filterModel._IsDeletes.Count > 0)
            {
                where = where.And(x => filterModel._IsDeletes.Contains(x.IsDelete));
            }
            
            //创建时间
            if (filterModel._CreateDate.HasValue)
            {
                where = where.And(x => x.CreateDate == filterModel._CreateDate.Value);
            }
            if (filterModel._CreateDate_Begin.HasValue)
            {
                where = where.And(x => x.CreateDate >= filterModel._CreateDate_Begin.Value);
            }
            if (filterModel._CreateDate_End.HasValue)
            {
                where = where.And(x => x.CreateDate < filterModel._CreateDate_End.Value.AddDays(1));
            }

            return where;
        }
        #endregion
    }
}

